#@weiXinLayout("活动")

#define weiXinMain()
#@navBar("活动列表",contextPath+"/weixin/")
<div id="content">

</div>
#end

#define weiXinCss()
#end

#define weiXinJs()

<script type="text/x-mustache" id="template">
    {{#items.list}}
    <div class="activity-item" data-url="#(contenxtPath)/weixin/activity/activityDetail?id={{id}}">
            <img class="slide-item" src="{{cover}}">
            <div class="activity-item-title" >{{name}}</div>
            <p class="activity-item-desc">{{desc}}</p>
            <div class="activity-bottom-container">
                <img class="icon-avatar" src="{{avatar}}">
                <span class="item-price">￥{{price}}/人<span class="status">{{status}}</span></span>
            </div>
        </div>
    {{/items.list}}
</script>
<script>
    $(document).ready(function(){
        var pageNum = 1;
        var totalPage =1;
        $(document.body).infinite(50);
        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            pageNum =pageNum+1;
            if(pageNum<=totalPage){
                initData(pageNum);
            }else{
                $.toast("加载完毕...")
            }
        });


        function initData(pageNum){
            var config ={
                "url":"#(contextPath)/weixin/activity/ajaxActivity",
                "data":{pageNum:pageNum},
                "successCallBack":function(resp){
                    if(resp.result){
                        var temp = $("#template").html();
                        var content = Mustache.render(temp,{items:resp.data.activityList});
                        $("#content").append(content);
                        loading = false;
                        totalPage = resp.data.totalPage
                    }
                }
            }
            var ajax = new AjaxUtils(config);
            ajax.executeRequest();
        }


        $("#content").on('click',".activity-item",function(){
            var url = $(this).attr("data-url");
            window.location.href=url;
        });

        initData(pageNum)
    });
</script>
#end